﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PriceLibrary.PriceService;


namespace VDataAdapter
{
 
    
    
    /// <summary>
    /// lưu giữ thông tin mới nhất của bảng giá và update mỗi khi có thay đổi ở số mã hay index nào đó 
    /// </summary>
    public class DataSource
    {
        //IDictionary<string, StockBase> =IDictionary<Ticker, StockInfoStatic || StockInfoDyns || ...>

        public DataSource()
        {

            _top3Prices = new Dictionary<string, StockBase>();
            _transactions = new Dictionary<string, PriceLibrary.ChartService.Transaction>();
            _basePrices = new Dictionary<string, StockBase>();
            _marketInfos = new Dictionary<int, StockBase>();
            _pttransactions = new Dictionary<string, PriceLibrary.PriceService.Transaction>();
            _ptTopPriceBuy = new Dictionary<string, StockBase>();
            _ptTopPriceSell = new Dictionary<string, StockBase>();
        }

        /// <summary>
        /// Lưu 3 giá, giá khớp, khối lượng khớp giá mở của, giá đóng cửa, ...
        /// </summary>
        private IDictionary<string, StockBase> _top3Prices;

        /// <summary>
        /// Lưu giữ thông tin vè thị trường
        /// </summary>
        private IDictionary<int, StockBase> _marketInfos;

        /// <summary>
        /// Lưu giữ thông tin vè transaction
        /// </summary>
        private IDictionary<string, PriceLibrary.ChartService.Transaction> _transactions;


        /// <summary>
        /// Lưu giữ thông tin vè transaction
        /// </summary>
        private IDictionary<string, PriceLibrary.PriceService.Transaction> _pttransactions;

        /// <summary>
        /// Lưu kết quả khớp lệnh theo thời gian, ...
        /// </summary>
        public IDictionary<string, PriceLibrary.PriceService.Transaction> PtTransactions
        {
            get { return _pttransactions; }
        }

        /// <summary>
        /// Nơi lưu giá trần, sàn, tham chiếu,..
        /// Chỉ được read-only, các update phải thông qua init hoặc function update
        /// </summary>
        /// 
        private IDictionary<string, StockBase> _basePrices;        
        public IDictionary<string, StockBase> BasePrices
        {
            get { return _basePrices; }            
        }

        /// <summary>
        /// Lưu 3 giá, giá khớp, khối lượng khớp giá mở của, giá đóng cửa, ...
        /// </summary>
        public IDictionary<string, StockBase> Top3Prices
        {
            get { return _top3Prices; }            
        }

        /// <summary>
        /// Lưu giữ thông tin vè thị trường
        /// </summary>
        public IDictionary<int, StockBase> MarketInfos
        {
            get { return _marketInfos; }             
        }

        /// <summary>
        /// Lưu kết quả khớp lệnh theo thời gian, ...
        /// </summary>
        public  IDictionary<string, PriceLibrary.ChartService.Transaction> Transactions
        {
            get { return _transactions; }            
        }

        /// <summary>
        /// Lưu đặt mua của giao dịch thỏa thuận, ...
        /// </summary>
        private IDictionary<string, StockBase> _ptTopPriceBuy;
        public IDictionary<string, StockBase> PtTopPriceBuy
        {
            get { return _ptTopPriceBuy; }
        }

        /// <summary>
        /// Lưu đặt bán của giao dịch thỏa thuận, ...
        /// </summary>
        private IDictionary<string, StockBase> _ptTopPriceSell;
        public IDictionary<string, StockBase> PtTopPriceSell
        {
            get { return _ptTopPriceSell; }
        }

        // update a base price, if not in the list, add it to the list
        public void UpdateStockBase(StockInfoStatic baseprice)
        {
            string symbol = baseprice.StockSymbol;
            _basePrices[symbol] = baseprice;
        }

        public void UpdateStockDynamic(StockInfoDyns baseprice)
        {
            string symbol = baseprice.StockSymbol;
            _top3Prices[symbol] = baseprice;
        }

        public void UpdateMarketInfo(MarketInfo baseprice)
        {            
            int floorcode = baseprice.FloorCode;             
            MarketInfos[floorcode] = baseprice;           
        }         

        // update transaction list when receive a new transaction
        // throw exception if item is not in the list
        public void UpdateTransaction(PriceLibrary.ChartService.Transaction baseprice) 
        {             
            string symbol = baseprice.Symbol;
            Transactions[symbol] = baseprice;           
        }

        public void UpdatePutTopPriceBuy(StockInfoDyns baseprice)
        {
            string symbol = baseprice.StockSymbol;
            _ptTopPriceBuy[symbol] = baseprice;
        }

        public void UpdatePutTopPriceSell(StockInfoDyns baseprice)
        {
            string symbol = baseprice.StockSymbol;
            _ptTopPriceSell[symbol] = baseprice;
        }


        public void UpdatePtTransaction(PriceLibrary.PriceService.Transaction baseprice)
        {
            string symbol = baseprice.Symbol;
            PtTransactions[symbol] = baseprice;
        }
    }
}
